/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jms;

import java.util.Properties;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import javax.naming.Context;
import javax.naming.InitialContext;

/**
 *
 * @author juanda
 */
public class Sender {
    public static void main(String[] args) throws Exception {
		// Gets the JNDI context
		Properties props = new Properties();
		props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.apache.activemq.jndi.ActiveMQInitialContextFactory");
		props.setProperty(Context.PROVIDER_URL,"tcp://fenixlaptop:61616?jms.useAsyncSend=true");
		//	props.setProperty("topic.Prueba","jca:/org.apache.geronimo.configs/activemq-ra/JCAManagedConnectionFactory/DefaultActiveMQConnectionFactory");
		props.setProperty("topic.Prueba","Prueba");
		Context jndiContext = new InitialContext(props);
		// Looks up the administered objects
		ConnectionFactory connectionFactory = (ConnectionFactory) jndiContext.lookup("ConnectionFactory");
		Topic queue = (Topic) jndiContext.lookup("Prueba");
		// Creates the needed artifacts to connect to the queue
		Connection connection = connectionFactory.createConnection();
		Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
		MessageProducer producer = session.createProducer(queue);
		TextMessage message = session.createTextMessage();
		for(int i=0; i<1; i++)
		{
		    message.setText("Hay un problema con su vivienda");
		    producer.send(message);
		}
		connection.close();

    }
    
}
